import { MockMethod } from 'vite-plugin-mock';

// const demo ={
//     // 请求地址
//     url: string;
//     // 请求方式
//     method?: MethodType;
//     // 设置超时时间
//     timeout?: number;
//     // 状态吗
//     statusCode?:number;
//     // 响应数据（JSON）
//     response?: ((opt: { [key: string]: string; body: Record<string,any>; query:  Record<string,any>, headers: Record<string, any>; }) => any) | any;
//     // 响应（非JSON）
//     rawResponse?: (req: IncomingMessage, res: ServerResponse) => void;
//   }
export default [
  {
    url: '/api/get',
    method: 'get',
    response: () => {
      return {
        code: 0,
        data: {
          name: 'vben',
        },
      };
    },
  },
  {
    url: '/api/post',
    method: 'post',
    timeout: 2000,
    response: {
      code: 0,
      data: {
        name: 'vben',
      },
    },
  },
  {
    url: '/api/text',
    method: 'post',
    rawResponse: async (req, res) => {
      let reqbody = '';
      await new Promise(resolve => {
        req.on('data', chunk => {
          reqbody += chunk;
        });
        req.on('end', () => resolve(undefined));
      });
      res.setHeader('Content-Type', 'text/plain');
      res.statusCode = 200;
      res.end(`hello, ${reqbody}`);
    },
  },
] as MockMethod[];
